/*
    写入信息的具体实现。这里选择使用的csv格式记录。
*/

#include "../include/write.h"
#include <iostream>
void writeInfo(std::vector<CAR> car, std::vector<Student> stu, std::map<int,int> M)
{
    // 打开一个输出文件流
    std::string fileName = "./data/info.csv";
    std::ofstream file(fileName);
    if(!file.is_open())
    {
        std::cout << "未找到文件！" << std::endl;
        return;
    }
    // 将结构体数组写入文件

    // 提前写一行标题行，便于阅读
    file << "学号,姓名,智能小车编号,底盘驱动形式,底盘最小离地间隙(mm),底盘编号,最大行程(km),底盘型号,轮胎1型号,轮胎1尺寸(mm),轮胎2型号,轮胎2尺寸(mm),轮胎3型号,轮胎3尺寸(mm),轮胎4型号,轮胎4尺寸(mm),轮距(mm),最小转弯半径(m),轴距(mm),AI(TOPS),CUDA核心,显存(GB),AGX型号,存储(GB),Tensor CORE,摄像头,深度帧率,FOV-X,FOV-Y,双目摄像头型号,RGB帧率,RGB帧分辨率-X,RGB帧分辨率-Y,雷达通道数,雷达测试范围(m),多线激光雷达型号,雷达功耗(W),陀螺仪厂家,陀螺仪型号,显示屏型号,显示屏尺寸,电池充电时长(h),对外供电(V),参数" << std::endl;

    for (int i = 0; i < car.size(); i++)
    {   
        // i是小车下标，M[i]是学生下标
        // 写入同学信息
        int sId = M[i];
        file << stu[sId].studentID << "," << stu[sId].name  << ",";

        // 写入小车信息
        file << car[i].id << "," << car[i].basePlate.driveType << "," << car[i].basePlate.groundClearance << "," << car[i].basePlate.id << "," << car[i].basePlate.maxRange << "," 
             << car[i].basePlate.model << "," << car[i].basePlate.tires[0].modelT << "," << car[i].basePlate.tires[0].size << "," << car[i].basePlate.tires[1].modelT 
             << "," << car[i].basePlate.tires[1].size << "," << car[i].basePlate.tires[2].modelT << "," << car[i].basePlate.tires[2].size << "," << car[i].basePlate.tires[3].modelT 
             << "," << car[i].basePlate.tires[3].size << "," << car[i].basePlate.track << "," << car[i].basePlate.turningRadius << "," << car[i].basePlate.wheelbase << "," << car[i].agx.aiPerformance 
             << "," << car[i].agx.cudaCores << "," << car[i].agx.memory << "," << car[i].agx.model << "," << car[i].agx.storage << "," << car[i].agx.tensorCores
             << "," << car[i].binocularCamera.camera << "," << car[i].binocularCamera.depthFrameRate << "," << car[i].binocularCamera.fovX << "," << car[i].binocularCamera.fovY
             << "," << car[i].binocularCamera.model << "," << car[i].binocularCamera.rgbFrameRate << "," << car[i].binocularCamera.rgbResolutionX << "," << car[i].binocularCamera.rgbResolutionY
             << "," << car[i].ladar.channels << "," << car[i].ladar.maxRange << "," << car[i].ladar.model << "," << car[i].ladar.powerConsumed
             << "," << car[i].gyroscope.manufacturer << "," << car[i].gyroscope.model
             << "," << car[i].lcd.model << "," << car[i].lcd.size
             << "," << car[i].battery.chargingTime << "," << car[i].battery.outputVoltage << "," << car[i].battery.parameters;
        // 换行
        file << std::endl;
    }

    // 关闭文件流
    file.close();
}
